package org.jeecg.modules.system.permissions.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.system.permissions.entity.BikeSysUserApp;
import org.jeecg.modules.system.permissions.mapper.BikeSysUserAppMapper;
import org.jeecg.modules.system.permissions.service.IBikeSysUserAppService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;

/**
 * @Description: 运维菜单权限
 * @Author: 月月鸟
 * @Date:   2021-07-07
 * @Version: V1.0
 */
@Service
public class BikeSysUserAppServiceImpl extends ServiceImpl<BikeSysUserAppMapper, BikeSysUserApp> implements IBikeSysUserAppService {
    @Resource
    private BikeSysUserAppMapper bikeSysUserAppMapper;
    @Override
    public Result<?> addOrEdit(BikeSysUserApp bikeSysUserApp) {
        QueryWrapper<BikeSysUserApp> wrapper = new QueryWrapper<>();
        wrapper.eq("role_id",bikeSysUserApp.getRoleId());
        BikeSysUserApp userAppData = bikeSysUserAppMapper.selectOne(wrapper);
        if (userAppData!=null){
            userAppData.setRoleMenu(bikeSysUserApp.getRoleMenu());
            bikeSysUserAppMapper.updateById(userAppData);
            return Result.OK("修改成功");
        }else {
            bikeSysUserAppMapper.insert(bikeSysUserApp);
            return Result.OK("添加成功");
        }
    }
}
